// 用于主界面获取各个省份数据的api

let express = require('express');
let app = express();
let bodyParser = require('body-parser');

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());


let router = express.Router();

// 操作数据库的对象
let Provinces = require('./mongodb/provinicesModel.js');
// 连接mongodb数据库


//api/home  params=province  GET 请求
router.route('/api/home')
    .get( (req, res) => {
        let obj_province = new Provinces();
        let province = req.body.province;   // 获得省份数据
        if(province === '全部'){
            obj_province.find({});  // 查询所有省份存在的
        } else {
            obj_province.find({province: province}, (err, result) => {
                if(err)
                    res.send(err);
                res.json(result);
            });
        }

})


module.exports = router;